{include file="public/header" /}
<style type="text/css">
    .gray-bg {
        background: #fff;
    }

    .wrapper {
        padding: 0;
    }

    .image-item {
        margin-bottom: 20px;
        height: 284px;
        overflow: hidden;
    }

    .image-item div {
        width: 100%;
        overflow: hidden;
    }

    .image-item .img-top {
        height: 145px;
    }

    .image-item .img-bottom {
        margin-top: 8px;
        height: 43px;
    }

    .image-item .img-bottom select {
        width: 50%;
    }

    .image-item div img {
        width: 100%;
    }

    .image-item button {
        position: absolute;
        right: 15px;
        display: block;
    }

    #images-item {
        margin-left: 100px;
        margin-right: 100px;
    }
</style>
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="row">
        <form class="form-horizontal" method="post">
            <div class="col-sm-12">
                <div class="ibox-content">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">类型：</label>
                        <div class="col-sm-9">
                            <select name="type" class="form-control">
                                {foreach $config.type as $key => $item}
                                <option value="{$key}" {if isset($name.type) and $name.type eq $key}selected="selected"
                                        {/if}>{$item}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">分类：</label>
                        <div class="col-sm-9">
                            <select name="category_id" class="form-control">
                                <option value="">请选择分类...</option>
                                {foreach $config.category as $key => $item}
                                <option value="{$item.id}" {if isset($name.category_id) and $name.category_id eq
                                        $item.id}selected="selected" {
                                /if}>{$item.name}</option>
                                {/foreach}
                            </select>
                            <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 发布系统广播无需选择</span>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">置顶：</label>
                        <div class="col-sm-9">
                            <select name="is_top" class="form-control">
                                <option value="0">否</option>
                                <option value="1" {if isset($name.is_top) and $name.is_top eq 1}selected="selected" {
                                /if}>是</option>
                            </select>
                            <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 置顶将按发布时间从新到旧排序</span>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">用户ID：</label>
                        <div class="col-sm-9">
                            <input type="text" name="member_id" class="form-control"
                                   value="{if !empty($name.member_id)}{$name.member_id}{/if}"
                                   onkeyup="this.value = this.value.replace(/[^\d]/g,'')"/>
                            <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 发布系统广播无需填写</span>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 control-label">范围选择：</label>
                        <div class="col-sm-9">
                            <select id="choose" name="choose" class="form-control">
                                <option value="1" {if isset($name.date_type) && $name.date_type neq -1} selected="selected"{/if}>选择</option>
                                <option value="2" {if empty($name.date_type) || $name.date_type eq -1} selected="selected" {/if}>填写</option>

                            </select>
                        </div>
                    </div>



                    <div class="form-group date_time" id="date_time_1" {if empty($name.date_type) ||  $name.date_type eq -1} style="display: none;"{/if}>
                        <label class="col-sm-2 control-label">时间：</label>
                        <div class="col-sm-4">
                            <input type="text" name="date" class="layui-input" value="{if !empty($name.begin_date)}{$name.begin_date|date='Y-m-d'}{/if}" id="date" placeholder="开始时间">
                        </div>
                        <div class="col-sm-5">
                            <select name="date_type" class="form-control">
                                {foreach $choose_list as $key => $item}
                                <option value="{$key}" {if !empty($name.date_type) && $name.date_type eq $key} selected="selected" {/if}>{$item.name}</option>
                                {/foreach}
                            </select>
                        </div>

                    </div>

                    <div class="form-group date_time" {if isset($name.date_type) && $name.date_type neq -1} style="display: none;"{/if}id="date_time_2">
                        <label class="col-sm-2 control-label">时间范围：</label>
                        <div class="col-sm-4">
                            <input type="text" name="begin_date" class="layui-input" id="begin_date" value="{if !empty($name.begin_date)}{$name.begin_date|date='Y-m-d H:i:s'}{/if}" placeholder="开始时间">
                        </div>
                        <div class="col-sm-4">
                            <input type="text" name="end_date" class="layui-input" id="end_time"  value="{if !empty($name.end_date)}{$name.end_date|date='Y-m-d H:i:s'}{/if}" placeholder="结束时间">
                        </div>
                        <div class="col-sm-1">
                            &nbsp;
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 control-label">地点：</label>
                        <div class="col-sm-9">
                            <input type="text" name="location" class="form-control" placeholder="地点（例如：广州市）"
                                   value="{$name.location|default=""}" />
                            <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 发布系统广播无需填写</span>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">内容：</label>
                        <div class="col-sm-9">
                            <textarea name="content" class="form-control" rows="3"
                                      cols="20">{$name.content|default=""}</textarea>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">图片集：</label>
                        <div class="col-sm-9">
                            <div id="demo"></div>
                        </div>
                    </div>
                    <input type="hidden" name="id" value="{$name.id|default=" 0"}" />
                    <input type="hidden" name="image_ids" value="{:implode(',', array_keys($file))}"/>
                    <div class="form-group" id="images-item">
                        {foreach $file as $id => $item}
                        <div class="col-md-3 col-sm-4 col-xs-6 image-item" id="file{$id}">
                            <button type="button" class="btn btn btn-sm btn-danger" onclick="delImg({$id})"><i
                                    class="fa fa-trash"></i> 删除
                            </button>
                            <div class="img-top"><img src="{$item.url}"/></div>
                            <div class="img-bottom">
                                <label class="col-sm-6 control-label">图片状态：</label>
                                <select class="form-control" name="file[{$id}][status]">
                                    <option value="1">正常</option>
                                    <option value="2" {if $item.status eq 2}selected="selected" {/if}>违规</option>
                                </select>
                            </div>
                            <textarea style="resize:none;" class="form-control" name="file[{$id}][remark]" rows="3">{$item.remark}</textarea>
                        </div>
                        {/foreach}
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>
{include file="public/footer" /}
{load href="__STYLE__/admin/plugins/iCheck/icheck.min.js"}
{load href="__STYLE__/admin/plugins/iCheck/custom.css"}
<!-- 引用控制层插件样式 -->
{load href="__STYLE__/admin/plugins/zyUpload/zyUpload.css"}
<!-- 引用核心层插件 -->
{load href="__STYLE__/admin/plugins/zyUpload/zyUpload.js"}
<script type="text/javascript">
    layui.use('laydate', function () {
        //时间选择器
        layui.laydate.render({
            elem: '#begin_date'
            , type: 'datetime'
        });
        layui.laydate.render({
            elem: '#end_time'
            , type: 'datetime'
        });
        layui.laydate.render({
            elem: '#date'
        });
    });
    var urlupload = "{:url('file/uploadImages', ['path' => 'content', 'fileType' => 5])}";

    function callback(res) {
        var html = '<div class="col-md-3 col-sm-4 col-xs-6 image-item" id="file' + res.id + '">';
        html += '<button type="button" class="btn btn btn-sm btn-danger" onclick="delImg(' + res.id + ')"><i class="fa fa-trash"></i> 删除</button>';
        html += '<div class="img-top"><img src="' + res.img + '" /></div>';
        html += '<div class="img-bottom">';
        html += '<label class="col-sm-6 control-label">图片状态：</label>';
        html += '<select class="form-control" name="file[' + res.id + '][status]">';
        html += '<option value="1">正常</option><option value="2">违规</option>';
        html += '</select>';
        html += '</div>';
        html += '<textarea style="resize:none;" class="form-control" name="file[' + res.id + '][remark]" rows="3"></textarea>';
        html += '</div>';
        $("#images-item").append(html);
        var image_ids = $("input[name='image_ids']").val();
        if (image_ids.length > 0) image_ids += ',';
        image_ids += res.id;
        $("input[name='image_ids']").val(image_ids);
    }

    function delImg(id) {
        layer.confirm('是否删除该照片', {
            btn: ['确定', '取消']
        }, function (index) {
            layer.close(index);
            $("#images-item").find('#file' + id).remove();
        });
    }

    $("#choose").change(function () {
        var choose_val = $(this).val();
        $(".date_time").hide();
        $("#date_time_" + choose_val).show();
    });

</script>
<script type="text/javascript" src="__STYLE__/admin/plugins/zyUpload/script.js?ver=20200527"></script>
{include file="public/bottom" /}